package com.dtagri.fjwlw.adapter.viewholders;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * ViewHolder抽象类,用于将ListView等列表视图的ViewHolder抽象画
 * 
 * @author wxjn
 * 
 */
public abstract class ViewHolder implements ViewParser {
	public View itemView;
	protected Context mContext;

	@Override
	public final View inflate(Context context, ViewGroup parent,
			boolean attachToRoot) {
		mContext = context;
		itemView = LayoutInflater.from(context).inflate(getItemLayout(),
				parent, attachToRoot);
		// 设置tag
		itemView.setTag(this);
		initWidgets();
		return itemView;
	}

	/**
	 * 获取ItemView的布局Id
	 * 
	 * @return Item View布局
	 */
	protected abstract int getItemLayout();

	/**
	 * 初始化各个子视图
	 */
	protected void initWidgets() {

	}

	public View findViewById(int id) {
		return itemView.findViewById(id);
	}

}
